/*
 * @LastEditTime: 2023-03-31 23:30:21
 * @Method: 
 * @Description: 
 */
import java.util.*;

package CodeTop;

public class Solution78 {
    List<List<Integer>> res = new LinkedList<>();
    LinkedList<Integer> path = new LinkedList<>(); 

    public List<List<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);
        dfs(nums, 0);
        return res;
    }

    public void dfs (int[] nums, int startIndex) {
        if (startIndex > nums.length) {
            return;
        }
        res.add(new LinkedList<>(path));
        for (int i = startIndex;i < nums.length;i++) {
            path.add(nums[i]);
            dfs(nums, i + 1);
            path.removeLast();
        }
    }
}
